package com.pfzy.ui.activity.tabtool

import android.R
import android.content.Context
import android.graphics.Typeface
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.pfzy.ui.databinding.ActivityTabtoolBinding
import com.pfzy.ui.view.tablayout.OnTabClickListener
import q.rorbin.badgeview.Badge
import q.rorbin.badgeview.QBadgeView
import java.util.*

class TabToolActivity : AppCompatActivity(){
    private lateinit var mBind: ActivityTabtoolBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBind = ActivityTabtoolBinding.inflate(layoutInflater)
        setContentView(mBind.root)
        initView()
    }

    private fun initView() {
        val tabTextList: MutableList<String> = ArrayList<String>() as MutableList<String>

        tabTextList.add("推荐学习");
        tabTextList.add("企业学院");
        tabTextList.add("我的关注");
        mBind.mYPKTabLayoutView.setTabTextList(tabTextList);
        mBind.mYPKTabLayoutView.addTabSelectedListener(object : OnTabClickListener {
            override fun tabSelectedListener(tabPosition: Int) {
                val makeText = Toast.makeText(this@TabToolActivity, "点击了第" + tabPosition + "项", Toast.LENGTH_SHORT)
                makeText.setGravity(Gravity.CENTER, 0, 0);
                makeText.show();
            }
        })

        val tabTextList2: MutableList<String> = ArrayList<String>()
        tabTextList2.add("全部");
        tabTextList2.add("待发货");
        tabTextList2.add("待收货");
        tabTextList2.add("待评价");
        mBind.mYPKTabLayoutView2.setTabTextList(tabTextList2);
        mBind.mYPKTabLayoutView2.setTabTextStyle(Typeface.BOLD)
        mBind.mYPKTabLayoutView2.setSelectTab(1)//设置默认选中第二tab

        val tabTextList3: MutableList<String> = ArrayList<String>()
        tabTextList3.add("首页");
        tabTextList3.add("关注");
        mBind.mYPKTabLayoutView3.setTabTextList(tabTextList3);

        val tabTextList4: MutableList<String> = ArrayList<String>()
        tabTextList4.add("Java1");
        tabTextList4.add("Java2");
        tabTextList4.add("Java3");
        tabTextList4.add("Java4");
        mBind.mYPKTabLayoutView4.setTabTextList(tabTextList4);

        val tabTextList5: MutableList<String> = ArrayList<String>()
        tabTextList5.add("查询行程");
        tabTextList5.add("实名认证");
        mBind.mYPKTabLayoutView5.setTabTextList(tabTextList5);
    }

    private var qBadgeView: Badge? = null

    /**
     * 右上小红点数量提示
     * @param context  当前activity
     * @param view  要显示在那个空间上的View
     * @param i 数量
     */
    fun QBadge(context: Context?, view: View?, i: Int) {
        qBadgeView = QBadgeView(context)
            .bindTarget(view)
            .setBadgeNumber(i) //角标数值
            .setBadgeBackgroundColor(ContextCompat.getColor(this, R.color.holo_red_light)) //角标背景色
            .setBadgeTextColor(ContextCompat.getColor(this, R.color.white)) //角标数值字体颜色
            .setBadgeTextSize(10f, true) //角标数值字体大小
            .setBadgeGravity(Gravity.END or Gravity.TOP) //角标位置（可看源码进行设置）
            .setGravityOffset(40f, 3f, true) //位置
    }

}